﻿#ifndef VIDEO_TIME_LINE_H
#define VIDEO_TIME_LINE_H

#include <QWidget>
#include <QColor>
#include <QTime>

class VideoTime : public QWidget
{
    Q_OBJECT
public:
    enum TIMETYPE
    {
        TIME_HOUR_ONLY = 0x1,
        TIME_HOUR_MINUTE_5 = 0x2,
        TIME_HOUR_MINUTE_1 = 0x4
    };

    struct TimeRect
    {
        QTime startTime;
        QTime endTime;
        QString color;
    };

    explicit VideoTime(QWidget *parent = 0);

public:
    void setTextColor_(const QString& color) { textColor_ = {color}; }
    void setBgColor_(const QString& color) { bgColor_ = {color}; }
    void appendTimeRect(const TimeRect& timeR) { timeRectList_.append(timeR); }
    void appendTimeRect(const QTime& start, const QTime& end) { timeRectList_.append({start, end, "#e5e5ff"}); }
    void clearTimeRect() { timeRectList_.clear(); }
    void changedTimeRange(const quint32 start, const quint32 end) {
        startTime_ = start; endTime_ = end;
        currentStartTime_ = startTime_; currentEndTime_ = endTime_;
    }

protected:
    void paintEvent(QPaintEvent *) override;
    void wheelEvent(QWheelEvent *event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    void mousePressEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;
    bool event(QEvent *event) override;

    void hoverMoveEvent(QHoverEvent* event);

protected:
    void drawBg(QPainter *painter);
    void drawRuler(QPainter *painter);

private:
    QList<TimeRect> timeRectList_;
    QPoint startMovePos_;

    qreal secondStep_ {0.01}; // 每秒移动多少像素
    qreal scaleFactor_{1.0}; // 缩放系数


    TIMETYPE timeType_ { TIME_HOUR_ONLY };
    quint32 startTime_{ 0 }; // 秒数
    quint32 endTime_{ 86400 }; // 秒数
    quint32 currentStartTime_{ startTime_ }; // 移动之后最左侧开始时间
    quint32 currentEndTime_{ endTime_ };  // 移动之后最右侧开始时间

    QColor textColor_;       //文字颜色
    QColor bgColor_;         //背景颜色
};

#endif
